// 数据回显ajax
$.ajax({
    type: "post",
    url: "/js/showteaPage",
    data: null,
    dataType: "json",
    success: function (data) {
        let teashowdiv = document.querySelector(".teashowpage");
        teashowdiv.innerHTML = data;
    }
})
// 选择茶叶类型
function selectTea(teatype) {
    $.ajax({
        type: "post",
        url: "/js/selectTeaShowPage",
        data: null,
        dataType: "json",
        success: function (data) {
            let teaarr = JSON.parse(data);
            let getteaobj = [];
            for (let i = 0; i < teaarr.length; i++) {
                if (teaarr[i].teatype == teatype) {
                    getteaobj.push(teaarr[i]);
                }
                if (teatype == 7) {
                    getteaobj = teaarr;
                    break;
                }
            }
            let teashowdiv = document.querySelector(".teashowpage");
            let showPage = "";
            let tea = getteaobj;
            for (let i = 0; i < tea.length; i++) {
                showPage += `<div onclick="showTeaPage(${tea[i].teaid})">
                <a href="" ><img  src="../imgs/${tea[i].teaimg}"  alt="" ></a>
                <div class="teaname" onclick="showTeaPage(${tea[i].teaid})">${tea[i].teaname}</div>
                <p>￥${tea[i].teaprice}</p>
                <button onclick="showTeaPage(${tea[i].teaid})">→</button>
                </div>`
            }

            teashowdiv.innerHTML = showPage;
        }
    })
}
// 点击跳转显示茶页面
function showTeaPage(teaid) {
    $.ajax({
        type: "post",
        url: "/js/showTeaPageGetLocal",
        data: null,
        dataType: "json",
        success: function (data) {
            let getteaobj = [];
            let teaarr = JSON.parse(data);
            for (let i = 0; i < teaarr.length; i++) {
                if (teaarr[i].teaid == teaid) {
                    getteaobj.push(teaarr[i]);
                    break;
                }
            }
            localStorage.showTea = JSON.stringify(getteaobj);
            window.location.href = './showteapage.html';
        }
    })
}